import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          useMaterial3: false,
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text("Flutter App"),
          ),
          body: const MyHome(),
        )
    );
  }
}

class MyHome extends StatefulWidget {
  const MyHome({super.key});

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  //设置groupValue,每一组radio都必须设置一个
  List<bool> hobby = [false, false, false];

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: [
          const Text("爱好", style: TextStyle(fontSize: 16),),
          CheckboxListTile(
              title: const Text("篮球", style: TextStyle(fontSize: 16),),
              value: hobby[0],
              onChanged: (value) {
                setState(() {
                  hobby[0] = value!;
                });
              }
          ),
          CheckboxListTile(
              title: const Text("足球", style: TextStyle(fontSize: 16),),
              value: hobby[1],
              onChanged: (value) {
                setState(() {
                  hobby[1] = value!;
                });
              }
          ),
          CheckboxListTile(
              title: const Text("网球", style: TextStyle(fontSize: 16),),
              value: hobby[2],
              onChanged: (value) {
                setState(() {
                  hobby[2] = value!;
                });
              }
          )
        ],
      ),
    );
  }
}
